#include "ge/Engine.hpp"

class MyScene : public Scene {
public:

	TargetCamera camera;
	
	class MyModel : public Model {
	public:

		Mesh mesh;
		
		class MyMaterial : public Material{
		public:
		
			class MyTexture : public Texture{
			public:
			
				MyTexture(){
					loadPNG("ninja.png");
				}
				
			} texture;
			
			class MyNormalTexture : public Texture{
			public:
			
				MyNormalTexture(){
//					loadPNG("normalTexture.png");
				}
				
			} normalTexture;
		
			MyMaterial(){
				setTexture(&texture);
//				setNormalTexture(&normalTexture);
			}
			
		} material;
	
		MyModel(){
			setMesh(&mesh);
			setMaterial(&material);
			
			material.emission = 0.0f;
			
			mesh.load("tools/ms3d/ninja.mesh");
//			mesh.load("tools/ms3d/MaterialGroup.0.mesh");
		}
	
	} myModel;
	
	float n = 0.0f;
	
	virtual void onFrame(){
		
		float r = 3;
		
		camera.eye = glm::vec3(0,0,15);
		
//		myModel.material.setTextureOffsetX(myModel.material.getTextureOffset().x+0.0005);

		myModel.matrix = mat4(1);
		myModel.matrix = translate(myModel.matrix,vec3(0,0,0));
		myModel.matrix = rotate(myModel.matrix,n*10,vec3(0,1,0));
		myModel.matrix = rotate(myModel.matrix,n*20,vec3(0,0,1));

//		light1.setPosition(glm::vec3(0,-100,0));
//		light2.setPosition(glm::vec3(0,100,0));
	
		n+=0.00001f;

		r = 1;
//		light1.setPosition(glm::vec3(glm::sin(n)*r, 0,glm::cos(n)*r));
		light2.setPosition(glm::vec3(glm::cos(n)*r, glm::sin(n)*r, 3));
		light3.setPosition(glm::vec3(0, glm::sin(n*1.5)*r, glm::cos(n*1.5)*r));

		redraw();
	}
	
	virtual void onFps(unsigned int fps){
		char fpsString[32];
		sprintf(fpsString,"fps : %d",fps);
		engine.window.setTitle(fpsString);
	}
	
	Light light1;
	
	Light light2;

	Light light3;
	
	MyScene(){
		setCamera(&camera);
		light1.setDiffuse(glm::vec3(1,1,1));
		light2.setDiffuse(glm::vec3(1,1,1));
		light3.setDiffuse(glm::vec3(1,1,1));
		
		light1.setPosition(glm::vec3(-2,2,2));
//		light1.setRadius(3);
//		light1.setInnerRadius(2.5);
//		attachLight(&light1);
//		attachLight(&light2);
//		attachLight(&light3);
		layer(0).attachModel(&myModel);
	}

};

#include <glm/gtx/euler_angles.hpp>

int main(){
	MyScene* myScene = new MyScene();
	engine.play(myScene);
	delete myScene;
	return 0;
}
